import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    // meta: { isRouterAuth: true },
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    }]
  },

  {
    path: '/wares',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Wares',
        component: () => import('@/views/wares/index'),
        meta: { title: '商品管理', icon: 'el-icon-s-goods' }
      },
    ]
  },
  {
    path: '/style',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Style',
        component: () => import('@/views/style/index'),
        meta: { title: '款式管理', icon: 'el-icon-info' }
      },
    ]
  },
  {
    path: '/price',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Price',
        component: () => import('@/views/price/index'),
        meta: { title: '价格管理', icon: 'el-icon-s-marketing' }
      },
    ]
  },
  {
    path: '/brands',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Brands',
        component: () => import('@/views/brands/index'),
        meta: { title: '分类管理', icon: 'el-icon-menu' }
      },
    ]
  },



  {
    path: '/orders',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Orders',
        component: () => import('@/views/orders/index'),
        meta: { title: '订单管理', icon: 'el-icon-s-order'
        },
      }
    ]
  },

  {
    path: '/admin',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Admin',
        component: () => import('@/views/admin/index'),
        meta: { title: '管理员', icon: 'el-icon-user-solid' }
      }
    ]
  },

  {
    path: '/source',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Source',
        component: () => import('@/views/source/index'),
        meta: { title: '素材管理', icon: 'el-icon-s-finance' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]



const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})



const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
